<?php
/**
 * kol产品
 * (model)
 */

namespace App\Models\KolManage;


use App\Models\Product\ProductClassify;
use App\Models\Product\ProductSku;
use Illuminate\Database\Eloquent\Model;

class KolSku extends Model{

    protected $table = 'k_kol_sku';

    protected $guarded = [];


    /**
     * 状态
     */
    const STATUS_YES  = 1; //启用
    const STATUS_NO   = 2; //停用
    public static $_status = [
        self::STATUS_YES  => '启用',
        self::STATUS_NO   => '停用',
    ];

    public function sku(){
        return $this->belongsTo(ProductSku::class, 'psku_id');
    }

    public function classify(){
        return $this->belongsTo(ProductClassify::class, 'classify_id');
    }

    public function kol(){
        return $this->belongsTo(Kol::class, 'kol_code', 'kol_code');
    }

    public static function options($where = []){
        $query = $where ? self::query()->where([$where]) : self::query();
        return $query->where('status', self::STATUS_YES)->pluck('psku_id','id');
    }

    public static function getDownloadData($res)
    {
        foreach ($res as $model){
            $temp = [
                $model->kol->media_account ?? '',
                Kol::$_media_platform[$model->kol->media_platform] ?? '',
                $model->sku->psku_code ?? '',
                $model->sku->psku_cn ?? '',
                $model->classify->title ?? '',
                $model->remark ?? '',
                self::$_status[$model->status] ?? '',
            ];
            yield $temp;
        }
    }

}
